package com.example.dddsample.infrastructure.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;

import javax.annotation.Resource;

/**
 * @author: bebm
 * @date: 2022/4/6 16:29
 * @description:
 */
@Configuration
@Import({KafkaConsumerConfig.class,KafkaProducerConfig.class})
public class kafkaReplyConfig {

    @Resource
    private KafkaTemplate kafkaTemplate;

    @Resource
    private ConsumerFactory consumerFactory;

    @Bean("repllyContainerFactory")
    public ConcurrentKafkaListenerContainerFactory<Integer, String> repllyContainerFactory() {
        ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory);
        factory.setReplyTemplate(kafkaTemplate);
        return factory;
    }
}
